﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Infrastructure;
using Website.Interfaces;
using Website.Models;

namespace Website
{
    public class DependencyInjectionConfig
    {
        internal static void Register(ControllerBuilder controllerBuilder, HttpServerUtility httpServer)
        {
            controllerBuilder.SetControllerFactory(ConfigureFactory(httpServer));
        }

        private static IControllerFactory ConfigureFactory(HttpServerUtility httpServer)
        {
            // composition root, register all types with IoC container here.
            var container = new UnityContainer();

            container.RegisterType<IRedirectionManager, RedirectionManager>();
            container.RegisterType<IMembershipService, OpenIdMembershipService>();
            container.RegisterType<IImageManager, ImageManager>();

            string dataPath = httpServer.MapPath("~/App_Data/");
            container.RegisterInstance<IArtCollection>(new ArtCollection(dataPath));
            container.RegisterInstance<IAuthorizedUserManager>(new AuthorizedUserManager(dataPath));
            container.RegisterInstance<ISiteDefinitionManager>(new SiteDefinitionManager(dataPath, new CultureManager()));

            return new UnityControllerFactory(container);
        }
    }
}